<template>
  <div class="rightTopContent">
    <div v-if="data" id="rightTopLine" class="allWidthHeight" />
    <div v-else class="kong">暂无数据</div>
  </div>
</template>
<script>
// import echarts from 'echarts'
import * as echarts from "echarts";
export default {
  props: {},
  data() {
    return {
      myChart: null,
      data: {},
    };
  },
  watch: {},
  mounted() {},
  methods: {
    infoSize() {
      this.myChart.resize();
    },
    setEquipmentLine(data) {
      this.data = data;
      const option = {
        grid: {
          show: false,
          top: "15%",
          right: "5%",
          bottom: "15%",
          left: "10%",
        },
        xAxis: {
          type: "category",
          data: this.data.temperature.map((item) => item.name),
          axisLine: {
            lineStyle: {
              color: "#0B4074",
              width: 1,
              type: "solid",
            },
          },
          axisLabel: {
            color: "#fff",
          },
        },
        yAxis: {
          type: "value",
          axisLine: {
            show: true,
            lineStyle: {
              color: "#0B4074",
              width: 1,
              type: "solid",
            },
          },
          axisLabel: {
            color: "#fff",
          },
        },
        legend: {
          data: ["温度", "湿度", "粉尘", "可燃气体", "压力"],
          textStyle: {
            color: "#fff",
          },
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
          },
        },
        series: [
          {
            name: "温度",
            type: "line",
            data: this.data.temperature.map((item) => item.value),
            smooth: true,
            itemStyle: {
              color: "#FFD700",
            },
          },
          {
            name: "湿度",
            type: "line",
            data: this.data.humidity.map((item) => item.value),
            smooth: true,
            itemStyle: {
              color: "#00FFFF",
            },
          },
          {
            name: "粉尘",
            type: "line",
            data: this.data.dust.map((item) => item.value),
            smooth: true,
            itemStyle: {
              color: "#FF4500",
            },
          },
          {
            name: "可燃气体",
            type: "line",
            data: this.data.gas.map((item) => item.value),
            smooth: true,
            itemStyle: {
              color: "#7FFF00",
            },
          },
          {
            name: "压力",
            type: "line",
            data: this.data.pressure.map((item) => item.value),
            smooth: true,
            itemStyle: {
              color: "#8A2BE2",
            },
          },
          // {
          //   name: "Voc",
          //   type: "line", // 改为折线图
          //   data: this.data.voc.map((item) => item.value),
          //   smooth: true, // 平滑曲线
          //   itemStyle: {
          //     color: "#00FFFF",
          //   },
          // },
        ],
      };
      if (
        this.myChart != null &&
        this.myChart !== "" &&
        this.myChart !== undefined
      ) {
        this.myChart.dispose(); // 销毁
      }
      this.myChart = echarts.init(document.getElementById("rightTopLine"));
      this.myChart.clear();
      this.myChart.setOption(option, true);
      // this.myChart.on('click', function (param) {
      //   that.$emit('eqOverViewInfo', param['name'])
      // })
    },
  },
};
</script>
<style lang="scss" scoped>
.echartsDiv {
  height: 100%;
}
</style>
